/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * RSTechniqueElement.h
 *
 *  Created on: 2010/03/08
 *      Author: Alexandre Pires ( c.alexandre.pires@gmail.com )
 */

#ifndef RSTECHNIQUEELEMENT_H_
#define RSTECHNIQUEELEMENT_H_

#include "RSElement.h"

namespace Realsphere {

    class RSTechniqueElement : public Realsphere::RSElement {
        Q_OBJECT
        Q_PROPERTY ( QString _attr_sid READ ScopeId WRITE SetScopeId )
        public:
            RSTechniqueElement ( const QString& rTag,
                                 const QString& rScopeId = QString::null );

            virtual ~RSTechniqueElement () = 0;

        public:
            QString                     ScopeId () const;
            RSValueElement*             GetValueElement ( unsigned int rIndex );
            RSValueElement*             GetValueElement ( const QString& rScopeId );
            int                         IndexOf ( RSValueElement* rValueElement );
            unsigned int                ValueElementsSize ();
            RSValueElements             ValueElements () const;
            RSValueElementsIterator     ValueElementsIterator () const;
            bool                        IsRootElement() const;

        public slots:
            void                        SetScopeId ( const QString& rScopeId, bool rEmit = true );
            RSError                     AddValueElement ( RSValueElement* rValueElement );
            RSError                     RemoveValueElement ( RSValueElement* rValueElement );
            RSError                     RemoveValueElement ( unsigned int rIndex );
            RSError                     RemoveValueElement ( const QString& rScopeId );

        protected:
            RSError                     BeforeAddChildElement ( RSElement* rChild );
            RSError                     BeforeRemoveChildElement ( RSElement* rChild );
            bool                        AfterAddChildElement ( RSElement* rChild );
            bool                        AfterRemoveChildElement ( RSElement* rChild );

            virtual RSError             BeforeAddValueElementValidation ( RSValueElement* rValueElement );
            virtual RSError             BeforeRemoveValueElementValidation ( RSValueElement* rValueElement );
            virtual bool                AfterAddValueElementValidation ( RSValueElement* rValueElement );
            virtual bool                AfterRemoveValueElementValidation ( RSValueElement* rValueElement );

        signals:
            void                        ScopeIdChanged ( const QString& rScopeId );
            void                        ValueElementAdded ( RSValueElement* rValueElement );
            void                        ValueElementRemoved ( RSValueElement* rValueElement );
            void                        TechniqueElementChanged ();

        private:
            QString                     mScopeId;
            RSValueElements             mValueElements;
    };

}

#endif /* RSTECHNIQUEELEMENT_H_ */
